#include<iostream>
using namespace std;

struct ListNode {
    int val;
    ListNode* next;

};

ListNode* swapPairs(ListNode* head) {
    ListNode* newHead = new ListNode();

    newHead->next = nullptr;

    ListNode* curnewHead = newHead;

    ListNode* cur = head;

    int number = 0;

    while (cur)
    {
        number++;

        ListNode* curnewNext = curnewHead->next;

        curnewHead->next = cur;

        ListNode* curNext = cur->next;

        cur->next = curnewNext;

        cur = curNext;

        if (number == 2)
        {
            number = 0;
            curnewHead = (curnewHead->next)->next;
        }
    }
    return newHead->next;
}
int main()
{
    ListNode n1;
    ListNode n2;
    ListNode n3;
    ListNode n4;
    n1.next = &n2;
    n2.next = &n3;
    n3.next = &n4;
    n4.next = nullptr;
    n1.val = 1;
    n2.val = 2;
    n3.val = 3;
    n4.val = 4;
    swapPairs(&n1);
	return 0;
}